//存放app 全局对象

import 'package:codemode/utils/sp_util.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'constants/Constants.dart';
import 'models/sys_user_entity.dart';

class AppModel {
  // 工厂模式
  factory AppModel() => _getInstance();

  static AppModel get instance => _getInstance();
  static AppModel _instance;

  //路由
  static FluroRouter router;

  String versionName; // 版本名称
  String platformName; //平台名称 android ios

  static AppModel _getInstance() {
    if (_instance == null) {
      _instance = new AppModel._internal();
    }
    return _instance;
  }

  SysUserEntity _usermodel;

  AppModel._internal() {
    // 初始化
//    SpUtil.putString(Constants.USERINFO, json.encode(data));
    String userString = SpUtil.getString(Constants.USERINFO, defValue: "");
    // if (userString != "") {
    //   UserModelEntity userModelsEntity=new UserModelEntity();
    //   userModelsEntity= userModelsEntity.fromJson(json.decode(userString));
    //   _usermodel =userModelsEntity;
    // }

    // PackageInfo.fromPlatform().then((value) => {versionName = value.version});
    // if (Platform.isAndroid) {
    //   platformName = 'android';
    // } else {
    //   platformName = 'ios';
    // }
    // String _version = getFlatForm;
  }

  get getUserModel => _usermodel;

  static initScreen(BuildContext context) {
    // 初始化
    ScreenUtil.init(
      // 设备像素大小(必须在首页中获取)
      BoxConstraints(
        maxWidth: MediaQuery.of(context).size.width,
        maxHeight: MediaQuery.of(context).size.height,
      ),
      // 设计尺寸
      designSize: Size(750, 1334),
      allowFontScaling: false,
    );
  }

  set usermodel(SysUserEntity value) {
    _usermodel = value;
  }
}
